package com.wll.thread.demo;

import java.util.concurrent.Future;

/**
 * @Description: TODO
 * @Author: Wanglulu
 * @Date: 2021/4/16 17:20
 * @Version 0.0.1
 */
public class TestThread {


    public static void main(String[] args) throws Exception {
        SquareCalculator squareCalculator = new SquareCalculator();
        Future<Object> future1 = squareCalculator.calculate(10);
        Future<Object> future2 = squareCalculator.calculate(100);
        Future<Object> future3 = squareCalculator.calculate(50);
        while (!(future1.isDone() && future2.isDone() && future3.isDone())) {
            System.out.println(
                    String.format(
                            "future1 is %s and future2 is %s",
                            future1.isDone() ? "done" : "not done",
                            future2.isDone() ? "done" : "not done"
                    )
            );
            Thread.sleep(300);
        }
        String result1 = (String) future1.get();
        String result2 = (String) future2.get();
        String result3 = (String) future3.get();
        System.out.println(" result1 - " + result1);
        System.out.println(" result2 - " + result2);
        System.out.println(" result3 - " + result3);
        squareCalculator.shutdown();
    }

}
